//
//  ImageCell.m
//  USB_Reader
//
//  Created by why on 15-3-24.
//  Copyright (c) 2015年 Tony_Wang. All rights reserved.
//

#import "ImageCell.h"


@interface ImageCell ()



@property (nonatomic, retain) UIImageView *myImage;
@property (nonatomic, retain) UILabel *labelTitle;
@end


@implementation ImageCell

- (void)dealloc
{
    [_labelTitle release];
    [_myImage release];
    [_model release];
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.myImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.myImage];
        
        self.labelTitle = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelTitle];
//        _labelTitle.backgroundColor = [UIColor redColor];
//        _myImage.backgroundColor = [UIColor cyanColor];
        
        [_myImage release];
        [_labelTitle release];
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.frame.size.width;
    
    CGFloat height = self.contentView.frame.size.height;
    
    self.myImage.frame = CGRectMake(20, 5, width/3, height-10);
   
    self.labelTitle.frame = CGRectMake(width/2 , 5, width/2, height-10);
    
    self.imageView.userInteractionEnabled = YES;
    self.myImage.layer.cornerRadius = 9;
    self.myImage.clipsToBounds = YES;
    

}

- (void)setModel:(ImageModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
   _labelTitle.text = self.model.title;
    NSString *str = [self.model.smallpic stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    _labelTitle.numberOfLines = 0;
    
    NSURL *url = [NSURL URLWithString:str];
    [_myImage setImageWithURL:url];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
